*the entropy weight method
//urban-rural modernization（Figure 2，Table A1，Table A8）
//X1 through X8 represent measurement indicators of the urban-rural modernization development level.
global all_var X1 X2 X3 X4 X5 X6 X7 
foreach i in $all_var{
egen min_`i'=min(`i')
egen max_`i'=max(`i')
gen s`i'=(`i'-min_`i')/(max_`i'-min_`i')  
replace s`i'=0.0001 if s`i'==0
}

global neg_var  X8 
foreach i in $neg_var{
egen min_`i'=min(`i')
egen max_`i'=max(`i')
gen s`i'=(max_`i'-`i')/(max_`i'-min_`i')
replace s`i'=0.0001 if s`i'==0
}
order  province year X* min* max* s*

forvalue i=1(1)8{ 
egen sums_`i'=sum(sX`i')
gen p`i'=sX`i'/sums_`i'
}
order  province  year X* min* max* s* sums* p* sX*

forvalue i=1(1)8{
egen l`i'=sum(p`i'*ln(p`i'))
gen e`i'=-l`i'/ln(390)  
gen d`i'=1-e`i'
}
order  province year X* min* max* s* sums* p* l* e* d*

forvalue i=1(1)8{
egen f`i'=rowtotal(d*)
gen w`i'=d`i'/f`i'
} 
order  province year X* min* max* s* sums* p* l* e* d* f* w*

forvalue i=1(1)8{
gen score`i'=w`i'*sX`i' 
}
egen Score = rowtotal(sc*)
keep province year  w* Score

//the Digital Economy（Figure 3，Table A9，Table A6）
//X1 through X22 are measurement indicators of the digital economy development level.
global all_var X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22
foreach i in $all_var{
egen min_`i'=min(`i')
egen max_`i'=max(`i')
gen s`i'=(`i'-min_`i')/(max_`i'-min_`i') 
replace s`i'=0.0001 if s`i'==0
}
order  province year X* min* max* s*
forvalue i=1(1)22{ 
egen sums_`i'=sum(sX`i')
gen p`i'=sX`i'/sums_`i'
}
order  id  year X* min* max* s* sums* p* sX*
forvalue i=1(1)22{
egen l`i'=sum(p`i'*ln(p`i'))
gen e`i'=-l`i'/ln(390)  
gen d`i'=1-e`i'
}
order  province year X* min* max* s* sums* p* l* e* d*
forvalue i=1(1)22{
egen f`i'=rowtotal(d*)
gen w`i'=d`i'/f`i'
} 
order  province year X* min* max* s* sums* p* l* e* d* f* w*
forvalue i=1(1)22{
gen score`i'=w`i'*sX`i' 
}
egen Score = rowtotal(sc*)
keep province year sX* w* Score

*the sensitivity analysis for the urban-rural modernization index（Tables 1 ）
forvalue i=1/8 {
    gen w`i'_original = w`i'
}
egen rank_Score_original = rank(Score_original)
local perturbations 0.01 0.05 0.10 
foreach pert in `perturbations' {  
    forvalue i=1/8 {
        replace w`i' = w`i'_original * (1 + `pert')
        egen temp_sum_up = rowtotal(w1 w2 w3 w4 w5 w6 w7 w8)
        forvalue j=1/8 {
            replace w`j' = w`j' / temp_sum_up
        }
        forvalue k=1/8 {
            replace score`k' = w`k' * sX`k'
        }
        egen Score_w`i'_up_`=100*`pert'' = rowtotal(score1 score2 score3 score4 score5 score6 score7 score8)
        replace w`i' = w`i'_original * (1 - `pert')
        egen temp_sum_down = rowtotal(w1 w2 w3 w4 w5 w6 w7 w8)
        forvalue j=1/8 {
            replace w`j' = w`j' / temp_sum_down
        }
        forvalue k=1/8 {
            replace score`k' = w`k' * sX`k'
        }
        egen Score_w`i'_down_`=100*`pert'' = rowtotal(score1 score2 score3 score4 score5 score6 score7 score8)
        forvalue j=1/8 {
            replace w`j' = w`j'_original
        }
        gen diff_w`i'_up_`=100*`pert'' = Score_w`i'_up_`=100*`pert'' - Score_original
        gen diff_w`i'_down_`=100*`pert'' = Score_w`i'_down_`=100*`pert'' - Score_original
        gen rel_diff_w`i'_up_`=100*`pert'' = (Score_w`i'_up_`=100*`pert'' - Score_original) / Score_original * 100
        gen rel_diff_w`i'_down_`=100*`pert'' = (Score_w`i'_down_`=100*`pert'' - Score_original) / Score_original * 100
        drop temp_sum_up temp_sum_down
    }
}

forvalue k=1/8 {
    replace score`k' = w`k'_original * sX`k'
}
replace Score = Score_original

local corr_vars Score_original
foreach pert in `perturbations' {
    local pert_pct = 100 * `pert'
    forvalue i=1/8 {
        local corr_vars `corr_vars' Score_w`i'_up_`pert_pct' Score_w`i'_down_`pert_pct'
    }
}
corr `corr_vars'
describe Score_w*_up_* Score_w*_down_*
list province year Score_original Score_w1_up_1 Score_w1_down_1 in 1/10
list province year diff_w1_up_1 diff_w1_down_1 in 1/10
sum rel_diff_w*_up_1 rel_diff_w*_down_1
sum rel_diff_w*_up_5 rel_diff_w*_down_5
sum rel_diff_w*_up_10 rel_diff_w*_down_10
sum diff_w*_up_1 diff_w*_down_1

*the sensitivity analysis for the digital economy development index（Tables 2）
forvalue i=1/22 {
    gen w`i'_original = w`i'
}
local perturbations 0.01 0.05 0.10 
foreach pert in `perturbations' {
    local pert_label = subinstr("`=100*`pert''", ".", "_", .)
    forvalue i=1/22 {
        replace w`i' = w`i' * (1 + `pert')
        egen temp_sum_up = rowtotal(w1-w22)
        forvalue j=1/22 {
            replace w`j' = w`j' / temp_sum_up
        }
        forvalue k=1/22 {
            replace score`k' = w`k' * sX`k'
        }
        egen Score_w`i'_up_`pert_label' = rowtotal(score1-score22)
        replace w`i' = w`i' * (1 - `pert')
        egen temp_sum_down = rowtotal(w1-w22)
        forvalue j=1/22 {
            replace w`j' = w`j' / temp_sum_down
        }
        forvalue k=1/22 {
            replace score`k' = w`k' * sX`k'
        }
        egen Score_w`i'_down_`pert_label' = rowtotal(score1-score22)
        forvalue j=1/22 {
            replace w`j' = w`j'
        }
        gen diff_w`i'_up_`pert_label' = Score_w`i'_up_`pert_label' - Score_original
        gen diff_w`i'_down_`pert_label' = Score_w`i'_down_`pert_label' - Score_original
        gen rel_diff_w`i'_up_`pert_label' = (Score_w`i'_up_`pert_label' - Score_original) / Score_original * 100
        gen rel_diff_w`i'_down_`pert_label' = (Score_w`i'_down_`pert_label' - Score_original) / Score_original * 100  
        drop temp_sum_up temp_sum_down
    }
}
local corr_vars Score_original
foreach pert in `perturbations' {
    local pert_pct = 100 * `pert'
    forvalue i=1/22 {
        local corr_vars `corr_vars' Score_w`i'_up_`pert_pct' Score_w`i'_down_`pert_pct'
    }
}
corr `corr_vars'
describe Score_w*_up_* Score_w*_down_*
list province year Score_original Score_w1_up_1 Score_w1_down_1 in 1/10
list province year diff_w1_up_1 diff_w1_down_1 in 1/10
sum rel_diff_w*_up_1 rel_diff_w*_down_1
sum rel_diff_w*_up_5 rel_diff_w*_down_5
sum rel_diff_w*_up_10 rel_diff_w*_down_10
sum diff_w*_up_1 diff_w*_down_1

*Correlation coefficients between the indices developed in this study and authoritative benchmarks（Table 3）
correlate y y1 x x1

* the panel Granger causality test（Table 4）
xtreg modern L.modern L.de czzcld eco scl ish, fe robust 
test L.de  
scalar F_de = r(F)
scalar p_de = r(p)
xtreg de L.de L.modern czzcld eco scl ish, fe robust  
test L.modern 
scalar F_modern = r(F)
scalar p_modern = r(p)

xtreg modern L.modern L2.modern L.de L2.de czzcld eco scl ish, fe robust 
test L.de L2.de 
scalar F_de = r(F)
scalar p_de = r(p)
xtreg de L.de L2.de L.modern L2.modern czzcld eco scl ish, fe robust
test L.modern L2.modern
scalar F_modern = r(F)
scalar p_modern = r(p)

xtreg modern L.modern L2.modern L3.modern L.de L2.de L3.de czzcld eco scl ish, fe robust 
test L.de L2.de L3.de L4.de
scalar F_de = r(F)
scalar p_de = r(p)
xtreg de L.de L2.de L3.de L.modern L2.modern L3.modern czzcld eco scl ish, fe robust  
test L.modern L2.modern L3.modern  
scalar F_modern = r(F)
scalar p_modern = r(p)

*Global Moran's I Test （Table 5）
spatwmat using w.dta,name(w)
spatgsa y2011 y2012 y2013 y2014 y2015 y2016 y2017 y2018 y2019 y2020 y2021 y2022 y2023,weights(w) moran
spatgsa x2011 x2012 x2013 x2014 x2015 x2016 x2017 x2018 x2019 x2020 x2021 x2022 x2023,weights(w) moran

*Local Moran's I for Urban-Rural Modernization Development（Figures 4）
spatwmat using w.dta,name(w)standardize
spatlsa y2011 ,weight(w) moran  graph(moran) symbol(id) id(pro) 
spatlsa y2015,weight(w) moran graph(moran) symbol(id) id(pro) 
spatlsa y2019,weight(w) moran  graph(moran) symbol(id) id(pro) 
spatlsa y2023,weight(w) moran  graph(moran) symbol(id) id(pro) 

*Local Moran's I for Digital Economy Development（Figures 5）
spatlsa x2011,weight(w) moran  graph(moran) symbol(id) id(pro) 
spatlsa x2015,weight(w) moran graph(moran) symbol(id) id(pro) 
spatlsa x2019,weight(w) moran  graph(moran) symbol(id) id(pro) 
spatlsa x2023,weight(w) moran  graph(moran) symbol(id) id(pro) 

//y, x, x1, x2, x3, and x4 represent URM, De, GID, ECO, SCL, and ISS, respectively.
*Model Selection（Table 6）
//LM
spcs2xt A-AD,matrix(aaa) time(13)  
spatwmat using aaaxt.dta,name(w) standardize
reg y x x1 x2 x3 x4
est store e1
spatdiag,w(w)
//Hausman 
spatwmat using w.dta,name(w) standardize
xsmle y x x1 x2 x3 x4, model(sdm) wmat(w) hausman nolog 
//LR    
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(ind) nolog noeffects
est store ind
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(time) nolog noeffects
est store time
xsmle  y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog noeffects 
est store both
lrtest both ind ,df(10) 
lrtest both time ,df(10) 
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog noeffects
est store sdm
xsmle  y x x1 x2 x3 x4,fe model(sar) wmat(w) type(both) nolog noeffects
est store sar
xsmle  y x x1 x2 x3 x4,fe model(sem) emat(w) type(both) nolog noeffects
est store sem
est store sem
lrtest sdm sar
lrtest sdm sem

*Parameter Estimation
//OLS（Table7 Column 1）
reg y x x1 x2 x3 x4
//2SLS （Table 7 Column2-3）
ivregress2 2sls y x x1 x2 x3 (x4 =z),first
est restore first
outreg2 using twostage.doc,cttop(first stage) bdec(4) replace
est restore second
outreg2 using twostage.doc,cttop(second stage) bdec(4)
//SDM（Table 7 Column4）
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog noeffects

*Spatial Effect Decomposition（Table 8）
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog effects

* Robustness Test（Table 9）
//Variable substitution（Table 9 Column 1）
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog noeffects
//Lagged explanatory variables（Table 9 Column2-4）
xtreg y L.x x1 x2 x3 x4 
xtreg y L2.x x1 x2 x3 x4
xtreg y L3.x x1 x2 x3 x4
//Alternative spatial weight matrices（Table 9 Column5-6）
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w1) type(both) nolog noeffects
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(w2) type(both) nolog noeffects

*Placebo test（Figure 6）
permute did_real beta = _b[did_real] se = _se[did_real] df = e(df_r) ,reps(1000) rseed(12345) saving("anweiji.dta",replace) : reghdfe y did_real 
         $controls , 
         absorb(id)
preserve
use anweiji.dta,clear
gen t_value = beta / se
gen p_value = 2 * ttail(df, abs(beta/se))
#delimit ;
twoway (scatter p_value beta)(kdensity beta, yaxis(2)), 
 xline(0.021, lc(black*0.5) lp(dash))
 xline(0, lc(black*0.5) lp(solid)) 
 yline(0.055, lc(black*0.5) lp(dash))
 xlabel(-0.025(0.025)0.025)
 xtitle("Estimator", size(*0.8)) xlabel(, format(%5.4f) labsize(small))
 ytitle("Density", size(*0.8)) ylabel(, nogrid format(%5.4f) labsize(small)) 
 ytitle("P Value", size(*0.8) axis(2)) ylabel(, nogrid format(%5.4f) labsize(small) axis(2))
 legend(r(1) order(1 "P Value" 2 "Estimator"))
 graphregion(color(white)) ;
restore

*Heterogeneity Analysis（Table 10）
spatwmat using D1.dta,name(D1)standardize
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(D1) type(both) nolog effects
spatwmat using D2.dta,name(D2)standardize
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(D2) type(both) nolog effects
spatwmat using D3.dta,name(D3)standardize
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(D3) type(both) nolog effects

*the subsample tests（Table 11）
spatwmat using W1.dta,name(W1)standardize
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(W1) type(both) nolog effects
spatwmat using W2.dta,name(W2)standardize
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(W2) type(both) nolog effects
spatwmat using W3.dta,name(W3)standardize
xsmle y x x1 x2 x3 x4,fe model(sdm) wmat(W3) type(both) nolog effects

*Dimensional Analysis（Table 12）
reg URM ID 
reg URM DI 
reg URM EN 
spatwmat using w.dta,name(w1)standardize
xsmle URM ID ,fe model(sdm) wmat(w) type(both) nolog effects
xsmle URM DI ,fe model(sdm) wmat(w) type(both) nolog effects
xsmle URM EN ,fe model(sdm) wmat(w) type(both) nolog effects

*Levels of Urban-Rural Modernization Development in China using PCA Method（Table A2）
foreach v of varlist var1-var8 {
    egen `v'_std = std(`v')
}
pca var1_std-var8_std
estat kmo  
matrix list e(Ev)  
local factors = 0
forval i = 1/`e(f)' {
    if el(e(Ev),1,`i') > 1 {
        local factors = `factors' + 1
    }
}

predict pc1-pc`factors', score
matrix E = e(Ev)
local total_variance = 0
forval i=1/`factors' {
    local total_variance = `total_variance' + el(E,1,`i')
}

gen composite_score = 0
forval i=1/`factors' {
    local weight = el(E,1,`i') / `total_variance'
    replace composite_score = composite_score + `weight' * pc`i'
}
keep province year composite_score pc*
order province year composite_score

* Levels of Digital Economy Development in China using PCA Method （Table A3）
foreach v of varlist var1-var22 {
    egen `v'_std = std(`v')
}
pca var1_std-var22_std
estat kmo 
matrix list e(Ev) 
local factors = 0
forval i = 1/`e(f)' {
    if el(e(Ev),1,`i') > 1 {
        local factors = `factors' + 1
    }
}
predict pc1-pc`factors', score
matrix E = e(Ev)
local total_variance = 0
forval i=1/`factors' {
    local total_variance = `total_variance' + el(E,1,`i')
}
gen composite_score = 0
forval i=1/`factors' {
    local weight = el(E,1,`i') / `total_variance'
    replace composite_score = composite_score + `weight' * pc`i'
}
keep province year composite_score pc*
order province year composite_score

*Parameter Estimation using PCA Method（Table A4）
reg y x x1 x2 x3 x4
ivregress2 2sls y x x1 x2 x3 (x4 =z),first
est restore first
outreg2 using PCAtwostage.doc,cttop(first stage) bdec(4) replace
est restore second
outreg2 using PCAtwostage.doc,cttop(second stage) bdec(4)
est restore second
xsmle  y x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog noeffects 

*Robustness Test（Table A5）
xsmle  y1 x x1 x2 x3 x4,fe model(sdm) wmat(w) type(both) nolog noeffects 
xsmle  y x x1 x2 x3 x4,fe model(sdm) wmat(w1) type(both) nolog noeffects 